package com.Jeu;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.SeekBar;
import android.widget.Toast;
import android.widget.SeekBar.OnSeekBarChangeListener;

//public class Options extends Activity {
//
//	MediaPlayer mediaPlayer;
//
//	/** Called when the activity is first created. */
//	@Override
//	public void onCreate(Bundle savedInstanceState) {
//		super.onCreate(savedInstanceState);
//		setContentView(R.layout.options);
//		init(this);
//
//		Button buttonBackground = (Button) findViewById(R.id.background);
//		Button buttonBackOptions = (Button) findViewById(R.id.backoptions);
//		buttonBackground.setOnClickListener(buttonBackgroundOnClickListener);
//		buttonBackOptions.setOnClickListener(buttonBackOptionsOnClickListener);
//	}
//
//	public void init(Context context) {
//		mediaPlayer = MediaPlayer.create(context, R.raw.fallbackring);
//		Button buttonPlayMediaPlayer = (Button) findViewById(R.id.playmediaplayer);
//		Button buttonPauseMediaPlayer = (Button) findViewById(R.id.pausemediaplayer);
//		buttonPlayMediaPlayer
//				.setOnClickListener(buttonPlayMediaPlayerOnClickListener);
//		buttonPauseMediaPlayer
//				.setOnClickListener(buttonPauseMediaPlayerOnClickListener);
//	}
//
//	Button.OnClickListener buttonBackOptionsOnClickListener = new Button.OnClickListener() {
//		@Override
//		public void onClick(View v) {
//			Intent MenuIntent = new Intent(Options.this, Menu.class);
//			startActivity(MenuIntent);
//		}
//	};
//
//	Button.OnClickListener buttonBackgroundOnClickListener = new Button.OnClickListener() {
//		@Override
//		public void onClick(View v) {
//			View optionsLayout = findViewById(R.id.options_layout);
//			optionsLayout.setBackgroundResource(R.drawable.background1);
//		}
//	};
//
//	Button.OnClickListener buttonPlayMediaPlayerOnClickListener = new Button.OnClickListener() {
//		@Override
//		public void onClick(View v) {
//			// TODO Auto-generated method stub
//			if (!mediaPlayer.isPlaying()) {
//				mediaPlayer.setLooping(true);
//				mediaPlayer.start();
//				// Toast.makeText(Options.this, "Enable", Toast.LENGTH_LONG)
//				// .show();
//			}
//		}
//	};
//
//	Button.OnClickListener buttonPauseMediaPlayerOnClickListener = new Button.OnClickListener() {
//		@Override
//		public void onClick(View v) {
//			// TODO Auto-generated method stub
//			if (mediaPlayer.isPlaying()) {
//				mediaPlayer.pause();
//				// Toast.makeText(Options.this, "Disable", Toast.LENGTH_LONG)
//				// .show();
//			}
//		}
//	};
//}

public class Options extends SubScreenActivity implements
		OnSeekBarChangeListener {
	public static final String PREF_FILE = "Jeu_pref";
	public static final String BG_MUSIC_VOLUME_KEY = "bgMusicVol";
	private SharedPreferences pref;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.setContentView(R.layout.options);
		((SeekBar) (findViewById(R.id.SoundSeekBar)))
				.setOnSeekBarChangeListener(this);
		((SeekBar) (findViewById(R.id.SoundSeekBar)))
				.setMax((int) (Audio.MAX_VOLUME * 100));
		((SeekBar) (findViewById(R.id.SoundSeekBar))).setProgress((int) (Audio
				.getVolume(R.raw.musicbackground) * 100));

		pref = getSharedPreferences(PREF_FILE, MODE_PRIVATE);
	}

	@Override
	public void onProgressChanged(SeekBar seekBar, int progress,
			boolean fromUser) {
		float currentVolume = (float) (seekBar.getProgress())
				/ (float) seekBar.getMax();
		Audio.setVolume(R.raw.musicbackground, currentVolume);
	}

	@Override
	public void onStartTrackingTouch(SeekBar seekBar) {
		// TODO Auto-generated method stub

	}

	@Override
	public void onStopTrackingTouch(SeekBar seekBar) {
		// TODO Auto-generated method stub

	}

	@Override
	public void onPause() {
		SharedPreferences.Editor editor = pref.edit();
		editor.putFloat(BG_MUSIC_VOLUME_KEY,
				Audio.getVolume(R.raw.musicbackground));
		editor.commit();
		super.onPause();
	}

}
